<template>
  <div class="loginPage">
    <div class="topContainer">
      <div class="welcome">欢迎登录安宁股份供应商管理系统</div>
      <div class="welcome_english">WELCOM!</div>
      <div class="bg">
        <img src="../img/login_bg.png" alt="" />
      </div>
    </div>
    <div class="centerContainer">
      <div class="loginName">
        <span class="loginName_icon"></span>
        <el-input
          v-model="loginName"
          placeholder="请输入账号/手机号"
        ></el-input>
      </div>
      <div class="password">
        <span class="password_icon"></span>
        <el-input
          v-model="password"
          placeholder="请输入密码"
          show-password
        ></el-input>
      </div>
      <div class="forgetPassword_box">
        <span class="forgetPassword" @click="goRetrievePassword">忘记密码</span>
      </div>
    </div>
    <div class="bottomContainer">
      <p class="loginBtn" @click="loginEvt">立即登录</p>
      <p class="registerBtn" @click="goRegister">立即注册</p>
    </div>
  </div>
</template>

<script>
import { login } from "@/apis/common.js";
export default {
  data() {
    return {
      loginName: "",
      password: "",
    };
  },
  mounted(){
    document.title = "安宁股份供应商登录"
  },
  methods: {
    // 跳转到注册页面
    goRegister() {
      this.$router.push("/register");
    },
    // 登录
    async loginEvt() {
      if (!this.loginName) {
        this.$message.error("账号不能为空！");
        return;
      }
      if (!this.password) {
        this.$message.error("密码不能为空");
        return;
      }
      await login({ loginName: this.loginName, password: this.password }).then(
        (res) => {
          console.log("登录：", res);
          if (res.code == 200) {
            window.open(res.redirectUrl, "_self");
          } else {
            this.password = "";
            this.$message.error(res.message);
          }
        }
      );
    },
    // 验证手机号
    validatePhoneNumber(loginName) {
      const regex = /^1[3-9]\d{9}$/;
      return regex.test(loginName);
    },
    // 忘记密码
    goRetrievePassword(){
      this.$router.push('/retrievePassword')
    }
},
};
</script>
<style lang="less" scoped>
.loginPage {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  .topContainer {
    width: 100%;
    height: 200px;
    .welcome {
      text-align: center;
      line-height: 40px;
      font-size: 24px;
    }
    .welcome_english {
      font-size: 18px;
      text-align: center;
      line-height: 50px;
    }
    .bg {
      width: 122px;
      height: 63px;
      margin: 0px auto;
      img {
        width: 100%;
        height: 63px;
      }
    }
  }
  .centerContainer {
    width: 320px;
    height: 200px;
    margin: 0 auto;
    .loginName {
      background: rgba(193, 210, 255, 0.4);
      margin-bottom: 20px;
      height: 50px;
      display: flex;
      border: 1px;
      border-radius: 5px;
      .loginName_icon {
        width: 50px;
        height: 50px;
        display: inline-block;
        background-image: url(../img/loginName_icon.png);
        background-size: 50%;
        background-repeat: no-repeat;
        background-position: center;
        position: relative;
      }
      .loginName_icon::after {
        content: "";
        width: 1px;
        height: 20px;
        position: absolute;
        background-color: #0728b9;
        right: 0px;
        top: 15px;
      }
      /deep/ .el-input {
        width: calc(100% - 50px);
        height: 50px;
        line-height: 50px;
        background-color: transparent;
        .el-input__inner {
          background-color: transparent;
          border: none;
          color: #0728b9;
          font-size: 16px;
        }
      }
    }
    .password {
      background: rgba(193, 210, 255, 0.4);
      height: 50px;
      display: flex;
      border: 1px;
      border-radius: 5px;
      .password_icon {
        width: 50px;
        height: 50px;
        display: inline-block;
        color: #0728b9;
        background-image: url(../img/password_icon.png);
        background-size: 50%;
        background-repeat: no-repeat;
        background-position: center;
        position: relative;
      }
      .password_icon::after {
        content: "";
        width: 1px;
        height: 20px;
        position: absolute;
        background-color: #0728b9;
        right: 0px;
        top: 15px;
      }
      /deep/ .el-input {
        height: 50px;
        line-height: 50px;
        width: calc(100% - 50px);
        background-color: transparent;
        .el-input__inner {
          background-color: transparent;
          border: none;
          color: #0728b9;
          font-size: 16px;
        }
      }
    }
    .forgetPassword_box {
      height: 40px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      .forgetPassword {
        color: #0728b9;
        font-size: 14px;
        cursor: pointer;
      }
    }
  }
  .bottomContainer {
    margin: 0 auto;
    width: 320px;
    height: 200px;
    .loginBtn {
      width: 100%;
      height: 46px;
      line-height: 46px;
      text-align: center;
      background-color: #1a30de;
      color: #fff;
      font-size: 16px;
      border: 1px solid #1a30de;
      border-radius: 4px;
      margin-bottom: 20px;
      cursor: pointer;
    }
    .registerBtn {
      width: 100%;
      height: 46px;
      line-height: 46px;
      text-align: center;
      background-color: #fff;
      color: #1a30de;
      font-size: 16px;
      border: 1px solid #1a30de;
      border-radius: 4px;
      cursor: pointer;
    }
  }
}
</style>